package org.sfx.interpreter

import javafx.scene.control.ContextMenu
import javafx.scene.control.MenuItem
import javafx.event.EventHandler
import javafx.event.ActionEvent
import org.sfx.control.ScrollableContextMenu

class CompletionMenu extends ScrollableContextMenu {
  def selectFrom(candidates: List[String])(f: String => Unit): Unit = {
    candidates.foreach { candidate =>
      this.getItems().addAll(new MenuItem(candidate) {
        this.setOnAction(new EventHandler[ActionEvent]() {
          def handle(actionEvent: ActionEvent): Unit = {
            f(candidate)
          }
        })
      })
    }
  }
}
